<template>
	<page>
    <view class="user-info">
      <view class="pic-name">
        <view class="pic">
          <image :src="info.user_info.avatar_pic"></image>
        </view>
        <view class="name">
          <text>{{info.user_info.nickname}}的红包</text>
        </view>
      </view>
      <view class="desc">
        <text>{{info.remark}}</text>
      </view>
    </view>
    <view class="package-price">
      <view class="price">
        <text>{{info.price}}</text>
        <text class="min">元</text>
      </view>
      <view class="more">
        <text v-if="info.user_id === userInfo.user_id && !recordList.length">等待对方领取</text>
        <text v-else-if="info.user_id === userInfo.user_id && recordList.length">对方已领取</text>
        <text v-else>已存入钱包，可发送红包</text>
        <text class="right-arrows"></text>
      </view>
    </view>
<!--    领取人数-->
    <view class="get-people">
      <view class="get-list">
        <view class="list" v-for="(item,index) in recordList" :key="index">
          <view class="pic">
            <image :src="item.user_info.avatar_pic"></image>
          </view>
          <view class="info">
            <view class="name-date">
              <view class="name">
                <text>{{item.user_info.nickname}}</text>
              </view>
              <view class="date">
                <text>{{item.create_time}}</text>
              </view>
            </view>
            <view class="price">
              <text>{{item.price}}元</text>
            </view>
          </view>
        </view>
      </view>
    </view>
	</page>
</template>

<script setup>

import {redPacketInfo, redPacketRecord} from "../../api/wallet";
import {onLoad} from "@dcloudio/uni-app";
import {getCurrentInstance, ref} from "vue";

const {proxy} = getCurrentInstance();

const userInfo = proxy.$global.userInfo;
const info = ref({
  user_info:{}
});
const recordList = ref([]);
// 参数
let red_packet_id = '';


onLoad((params) =>{
  red_packet_id = params.red_packet_id||'';
  getData();
  getRecord();
})
function getData(){
  redPacketInfo({
    red_packet_id: red_packet_id
  }).then(res =>{
    info.value = res.data;
  })
}

/**
 * 获取领取记录
 */
function getRecord(){
  redPacketRecord({
    red_packet_id: red_packet_id
  }).then(res =>{
    recordList.value = res.data;
  })
}
</script>

<style lang="scss">
  @import "RedPacketResult.scss";
</style>
